package com.jeff.tianti.cms.dao;

import com.jeff.tianti.cms.dto.font.PageBeanUid;
import com.jeff.tianti.cms.entity.ConsultCategory;
import com.jeff.tianti.common.dao.CustomBaseSqlDaoImpl;
import com.jeff.tianti.common.entity.PageModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jeff.tianti.cms.entity.Consult;
import com.jeff.tianti.cms.dto.ConsultQueryDTO;
import org.apache.commons.lang3.StringUtils;

/**
 * @author liuyi
 * @desc ConsultDaoImpl类
 * @date 2019-06-28
 */

public class ConsultDaoImpl extends CustomBaseSqlDaoImpl implements ConsultDaoCustom {

    public PageModel<Consult> queryConsultPage(ConsultQueryDTO consultQueryDTO) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder hql = new StringBuilder();
        hql.append(" select t from Consult t where 1 = 1 ");
        if (consultQueryDTO != null) {
            String state = consultQueryDTO.getState();
            if (StringUtils.isNotBlank(state) && !"-1".equals(state) ) {
                hql.append(" and t.state = :state ");
                map.put("state", state);
            }
        }
        hql.append(" order by t.createDate desc ");

        return this.queryForPageWithParams(hql.toString(), map, consultQueryDTO.getCurrentPage(), consultQueryDTO.getPageSize());
    }

    public List<Consult> queryConsultList(ConsultQueryDTO consultQueryDTO) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder hql = new StringBuilder();
        hql.append("select t from Consult t ");
        return this.queryByMapParams(hql.toString(), map);
    }


    @Override
    public PageModel<Consult> findByUid(PageBeanUid pageBean) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder hql = new StringBuilder();
        hql.append("select t from Consult t where 1=1 ");
        if (pageBean != null) {
            String uid = pageBean.getUid();
            if (StringUtils.isNotBlank(uid)) {
                hql.append(" and t.uid = :uid ");
                map.put("uid", uid);
            }
        }
        hql.append(" order by t.updateDate desc ");
        return this.queryForPageWithParams(hql.toString(), map, pageBean.getCurrentPage()+1, pageBean.getPageSize());
    }


}